<?php 
$sql =	"SELECT
			  c.page_id,
			  d.title,
			  d.description,
			  d.meta_key,
			  d.meta_description	
		  FROM
			  pages AS c,
			  page_description AS d
		  WHERE
		  
			  c.page_id = d.page_id
			  AND
			  d.lang_id = '".$_SESSION['lang_id']."'
			  AND
			  c.sef_url = '".$sef_url."' 
			  AND c.published
		  ";
$result = query($sql);
$row = mysql_fetch_object($result);


head(sth($row->title),sth($row->meta_description));



?>


		<div id="content">
			
			<div class="left full">
				<h1><?=stripslashes($row->title)?></h1>
				 
				<?=stripslashes($row->description)?>
                 
				<div id="city-opt" class="options">
				  <a href="#">Choose City</a>
				  
				</div>
				
				<div id="park-opt" class="options" style="display:none;" >
				  <a href="#">Choose Location</a>
				  
				</div>
				<br />
				<br />
                
                
                <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
				<script>
                    // This example adds a UI control allowing users to remove the
                    // polyline from the map.
                    
                    var flightPath;
                    var map;
                    
                    var zoom = 5;
                    var Latitude = 42.70513573810849;
                    var Longitude = 23.31751585006714;
                    function initialize() {
                      var mapOptions = {
                         zoom: zoom,
                        center: new google.maps.LatLng(Latitude,Longitude)
                      };
                    
                      map = new google.maps.Map(document.getElementById('map-canv'), mapOptions);
                    
                      
                    
                      //addLine();
                    }
                    
                    google.maps.Polygon.prototype.getBounds = function() {
					var bounds = new google.maps.LatLngBounds();
					var paths = this.getPaths();
					var path;        
					for (var i = 0; i < paths.getLength(); i++) {
						path = paths.getAt(i);
						for (var ii = 0; ii < path.getLength(); ii++) {
							bounds.extend(path.getAt(ii));
						}
					}
					return bounds;
				}
                    
                    google.maps.event.addDomListener(window, 'load', initialize);
                    
                        </script>
                                    
                
                <div id="map-canv" style=" width:100%; height:400px;"></div>

				
               <script>
			function print_r(o){
			return JSON.stringify(o,null,'\t').replace(/\n/g,'<br>').replace(/\t/g,'&nbsp;&nbsp;&nbsp;'); }
			
			$(document).ready(function() {
			
			var appname;
			var json;
			 $.ajax({
						type: 'GET',
						url: 'https://portal.olapark.pt/OlaParkUsersDataService.svc/GetAllParkSystems?<?=date('Y-m-d-g-i')?>',
						data: '',
						async: false,
						success: function(msg){
							
							json = JSON.parse(msg.GetAllParkSystemsResult);
							
							
							
						},
						error: function(msg){
							alert('Err:'+ msg)
						}
					});
			
			var curentcity = '';
			var curentapp = '';
			
			//Зарежда градовете		
				function loadcities(){
					
					$.each(json, function(index, value) {
						var tr = true;	
						$('#city-opt a').each(function() {
							
							if($(this).text() == value['City'])
							{
								tr = false;	
							}
						});
							if(tr)
							{
								$('#city-opt').append('<a href="#">'+value['City']+'</a>');
							}
						});
						
						
				}
			loadcities();
			//City clik function	
			$('#city-opt a').click(function(e){
					e.preventDefault();
					var value = $(this).text();	
					var option = $(this).attr('href');
					$(this).parent().find('a:first').text(value);
					$(this).parent().find('a:first').attr('href', option);
					
					
					loadpark($(this).text());
					});
					
				
				
				function loadpark(city)
				{
					if(curentcity != city)
					{
						curentcity =  city;
					$('#park-opt').html('<a href="#">Choose Location</a>');
					$.each(json, function(index, value) {
							
							
							if(city == value['City'])
							{
								Latitude = value['cityCenterLat'];
								Longitude = value['cityCenterLon'];
								zoom = 12;
								initialize() ;
								
								//map.setCenter(avalue['cityCenterLat'],Longitude = value['cityCenterLon']);
							   // map.fitBounds(12);
								
									$('#park-opt').append('<a  href="#">'+value['AppName']+'</a>');
									
									$('#park-opt').show();
									
									
									$('#park-opt a').click(function(e){
									e.preventDefault();
									
									var value = $(this).text();	
									var option = $(this).attr('href');
									$(this).parent().find('a:first').text(value);
									$(this).parent().find('a:first').attr('href', option);
									
									
									appname = $(this).text();
									//alert('zsfgadfg');
									loadtarif();
								
									});	
								}
								
							
							
							});
							
						}	
						
				}
				var overlays = new Array();
				function loadtarif()
				{
					if(curentapp != appname)
					{
						curentapp = appname;
						
						
					$.each(json, function(index, value) {
							
							
							if(appname == value['AppName'])
							{	
								/*var ov  =0;
								while(overlays){
								   overlays[ov].setMap(null);
								   ov++;
								  }*/
								
								var coordAll = new Array();
								
								var zones = value['Zones'];
								$.each(zones, function(index, val) {
								
								        $.each(val['SubZones'], function(index, valzon) {
											var coord = new Array();
											$.each(valzon['Geo'], function(index, valgeo) {
												coordAll.push(new google.maps.LatLng(Number(valgeo['Latitude']), Number(valgeo['Longitude'])));
											});
										});
								});
								allPoligon = new google.maps.Polygon({
												paths: coordAll,
												strokeColor: '#ffffff',
												strokeOpacity: 0,
												strokeWeight: 1,
												fillColor: '#ffffff',
												fillOpacity: 0
											  });
								
							 allPoligon.setMap(map);
							 overlays.push(allPoligon);
							 map.setCenter(allPoligon.getBounds().getCenter());
							 map.fitBounds(allPoligon.getBounds());			
							
							
							$.each(value['Zones'], function(index, val) {
										$.each(val['SubZones'], function(index, valzon) {
											var coord = new Array();
											
											$.each(valzon['Geo'], function(index, valgeo) {
												
												coord.push(new google.maps.LatLng(Number(valgeo['Latitude']), Number(valgeo['Longitude'])));
												
												
											});
											
											poligon = new google.maps.Polygon({
											paths: coord,
											strokeColor: val['ZoneColor'],
											strokeOpacity: 0.8,
											strokeWeight: 1,
											fillColor: val['ZoneColor'],
											fillOpacity: 0.50
										  });
										
										 poligon.setMap(map);
										 overlays.push(poligon);
										
										 
										 google.maps.event.addListener(poligon, 'click', function(event){
												
												 map.setCenter(this.getBounds().getCenter());
												 map.fitBounds(this.getBounds());
												
												var contentString = '<h5 style=" color:'+val['ZoneColor']+';">'+value['AppName']+' - '+val['ZoneName']+'</h5>  <b>Min. time:</b> '+val['MinParkTime']+' min ('+val['MinPrice']+' '+value['currSymbol']+')<br> <b>Max. time:</b> '+val['MaxParkTime']+' min ('+(val['MaxParkTime']/val['MinParkTime'])*val['MinPrice']+' '+value['currSymbol']+')<br> ';
											 
											  infoWindow.setContent(contentString);
											  infoWindow.setPosition(event.latLng);
											  infoWindow.open(map);
											 
											 });
											infoWindow = new google.maps.InfoWindow();
										});
									});	
							
							 }
							
						});
					}
					
				}
				
					
							
			});	
</script> 
               

                 
			</div>
           
			
		</div>
		
	
<?php

foot();
?>